﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using DevExpress.XtraEditors.Repository;
using System.Windows.Forms;
using System.Data;

namespace CIRDiagnoseDevice
{
    public class DevControlHelper
    {
        public static void DrawCheckBox(DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e, bool chk)
        {
            RepositoryItemCheckEdit repositoryCheck = e.Column.ColumnEdit as RepositoryItemCheckEdit;
            if (repositoryCheck != null)
            {
                Graphics g = e.Graphics;
                Rectangle r = e.Bounds;

                DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info;
                DevExpress.XtraEditors.Drawing.CheckEditPainter painter;
                DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs args;
                info = repositoryCheck.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo;

                painter = repositoryCheck.CreatePainter() as DevExpress.XtraEditors.Drawing.CheckEditPainter;
                info.EditValue = chk;
                info.Bounds = r;
                info.CalcViewInfo(g);
                args = new DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
                painter.Draw(args);
                args.Cache.Dispose();
            }
        }

        //public static bool ClickGridCheckBox(DevExpress.XtraGrid.Views.Grid.GridView gridView, string fieldName, bool currentStatus)
        //{
        //    bool result = false;
        //    if (gridView != null)
        //    {
        //        gridView.ClearSorting();//禁止排序

        //        gridView.PostEditor();
        //        DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo info;
        //        Point pt = gridView.GridControl.PointToClient(Control.MousePosition);
        //        info = gridView.CalcHitInfo(pt);
        //        if (info.InColumn && info.Column != null && info.Column.FieldName == fieldName)
        //        {
        //            for (int i = 0; i < gridView.RowCount; i++)
        //            {
        //                gridView.SetRowCellValue(i, fieldName, !currentStatus);
        //            }
        //            return true;
        //        }
        //    }
        //    return result;
        //}
    }
}
